﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using Common;

namespace WebApi
{
    public class LoginController:BaseController
    {
        private static List<UserInfo> UserInfos = new List<UserInfo>();
        private static int counts = 2;

        static LoginController()
        {
            UserInfos.Add(new UserInfo()
            {
                Id = 1,
                UserName = "kevin",
                UserPwd = "123456",
                
            });
            UserInfos.Add(new UserInfo()
            {
                Id = 2,
                UserName = "AngelGigi",
                UserPwd = "111111",
            });
             
        }


       [HttpPost]
        public HttpResponseMessage Login(UserInfo userinfo)
        {
             var resultmessage = new ResultMessage<UserInfo>();
           if (userinfo != null)
           {
               var list =
                   UserInfos.Where(m => m.UserName.ToLower() == userinfo.UserName.ToLower() && m.UserPwd == userinfo.UserPwd).ToList();

               if (list.Any())
               {
                   resultmessage.Data = list.SingleOrDefault();
                   resultmessage.Code = Status.Sucess.ToString();
               }
               else
               {
                   resultmessage.Message = "用户名或密码错误！";
                   resultmessage.Code = Status.Fail.ToString();
               }
           }
           else
           {
               resultmessage.Message = "参数错误！";
               resultmessage.Code = Status.Fail.ToString();
           }
           return Common.GetInstince().ToJsonResult(resultmessage);
        }
    }
}
